package com.example.wanted.controller;

import com.example.wanted.model.Comment;
import com.example.wanted.model.Question;
import com.example.wanted.service.CommentService;
import org.json.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

@RestController
public class CommentController {
    final CommentService commentService;

    @Autowired
    public CommentController(CommentService commentService) {
        this.commentService = commentService;
    }

    @PostMapping("comment")
    public void saveComment(@RequestBody Comment c, HttpServletResponse res, HttpServletRequest req) {
        System.out.println(c);
        commentService.save(c);
    }

    @GetMapping("get_comment_by_question")
    public Comment[] getCommentQuestion(@RequestParam Long question_id, HttpServletResponse res, HttpServletRequest req) {
        System.out.println(question_id);
//        System.out.println(commentService.findByQuestion(question_id).length);
        return commentService.findByQuestion(question_id);
    }
}
